<!--
描述：慕课模块-课程审核
开发人：zhaohang
开发日期：2019年11月7日
-->
<template lang="pug">
  kalix-dialog.user-add(title='开课' bizKey="moocClass" ref="kalixBizDialog" v-bind:formModel.sync="formModel" v-bind:targetURL="targetURL" :submitCustom="submitActionReactor")
    div.el-form(slot="dialogFormSlot")
      el-form-item(label="开课" prop="open")
        el-select(v-model="temp"  placeholder="请选择")
          el-option(v-for="item in option" v-bind:key="item.value" v-bind:value="item.value" v-bind:label="item.label")
</template>

<script type="text/ecmascript-6">
  import {moocClassURL, classNoticeURL} from '../../config.toml'
  import FormModel from './model'
  import Message from '../../../../../common/message'
  import EventBus from '../../../../../components/corelib/common/eventbus'
  import {ON_REFRESH_DATA} from '../../../../../components/corelib/components/common/event.toml'
  export default {
    name: 'moocClassOpen',
    data() {
      return {
        temp: null,
        fileList: [],
        formModel: Object.assign({}, FormModel),
        option: [{
          value: 1,
          label: '是'
        }, {
          value: 2,
          label: '否'
        }
        ],
        labelWidth: '120px',
        targetURL: moocClassURL
      }
    },
    methods: {
      submitActionReactor(baseDialog) { // 提交
        if (baseDialog.formModel.appraise === '否') {
          this.formModel.appraise = false
        } else {
          this.formModel.appraise = true
        }
        if (baseDialog.formModel.charge === '否') {
          this.formModel.charge = false
        } else {
          this.formModel.charge = true
        }
        if (baseDialog.formModel.recommend === '否') {
          this.formModel.recommend = false
        } else {
          this.formModel.recommend = true
        }
        if (baseDialog.formModel.isOpen === '通过') {
          this.formModel.isOpen = 1
        } else {
          this.formModel.isOpen = 2
        }
        // if (baseDialog.formModel.temp === '开课') {
        //   this.formModel.temp = 1
        // } else {
        //   this.formModel.temp = 2
        // }
        this.formModel.classOpen = this.temp
        if (baseDialog.formModel.classOpen === 1) {
          this.axios.request({
            method: 'PUT',
            url: moocClassURL + '/' + this.formModel.id,
            data: {
              id: this.formModel.id,
              className: this.formModel.className,
              classIntroduce: this.formModel.classIntroduce,
              teacherIntroduce: this.formModel.teacherIntroduce,
              classCover: this.formModel.classCover,
              departmentId: this.formModel.departmentId,
              specialityId: this.formModel.specialityId,
              classTypeId: this.formModel.classTypeId,
              isOpen: this.formModel.isOpen,
              appraise: this.formModel.appraise,
              charge: this.formModel.charge,
              openTime: this.formModel.openTime,
              browseNum: this.formModel.browseNum,
              teacherId: this.formModel.teacherId,
              classOpen: this.formModel.classOpen,
              judgeOpen: 't'
            }
          }).then(response => {
            this.axios.request({
              method: 'POST',
              url: classNoticeURL,
              data: {
                notice: '您申请的《' + this.formModel.className + '》课已通过审核！',
                personName: this.formModel.teacher,
                isnew: true
              }
            }).then(response => {
              if (response.data.success) {
                Message.success(response.data.msg)
                EventBus.$emit('moocClass' + '-' + 'KalixDialogClose')
              } else {
                Message.error(response.data.msg)
                EventBus.$emit('moocClass' + '-' + 'KalixDialogClose')
              }
              // }
              // 刷新列表
              console.log(' ===== BaseDialog ON_REFRESH_DATA ===== ', ON_REFRESH_DATA)
              EventBus.$emit(ON_REFRESH_DATA, 'moocClassExamine')
              console.log('[kalix] dialog submit button clicked !')
            })
          })
        } else {
          this.axios.request({
            method: 'PUT',
            url: moocClassURL + '/' + this.formModel.id,
            data: {
              id: this.formModel.id,
              className: this.formModel.className,
              classIntroduce: this.formModel.classIntroduce,
              teacherIntroduce: this.formModel.teacherIntroduce,
              classCover: this.formModel.classCover,
              departmentId: this.formModel.departmentId,
              specialityId: this.formModel.specialityId,
              classTypeId: this.formModel.classTypeId,
              isOpen: this.formModel.isOpen,
              appraise: this.formModel.appraise,
              charge: this.formModel.charge,
              openTime: this.formModel.openTime,
              browseNum: this.formModel.browseNum,
              classOpen: this.formModel.classOpen,
              judgeOpen: 't',
              teacherId: this.formModel.teacherId
            }
          }).then(response => {
            this.axios.request({
              method: 'POST',
              url: classNoticeURL,
              data: {
                notice: '您申请的《' + this.formModel.className + '》课未通过审核，详情进入课程管理查看！',
                personName: this.formModel.teacher
              }
            }).then(response => {
              if (response.data.success) {
                Message.success(response.data.msg)
                EventBus.$emit('moocClass' + '-' + 'KalixDialogClose')
              } else {
                Message.error(response.data.msg)
                EventBus.$emit('moocClass' + '-' + 'KalixDialogClose')
              }
              // 刷新列表
              console.log(' ===== BaseDialog ON_REFRESH_DATA ===== ', ON_REFRESH_DATA)
              EventBus.$emit(ON_REFRESH_DATA, 'moocClassExamine')
              console.log('[kalix] dialog submit button clicked !')
            })
          })
        }
      }
    }
  }
</script>

<style scoped lang="stylus" type="text/stylus">

</style>
